package com.itheima.service;

import com.itheima.bean.User;
import com.itheima.dao.UserMapper;
import com.itheima.dao.impl.UserImpl;

public class UserService {

    private final UserMapper userMapper = new UserImpl();

    //用户登录用  检查用户名和密码是否正确
    public User selectUser(String name, String passWord){
        return userMapper.selectUser(name, passWord);
    }
    //通过用户名查询用户是否存在
    public User selectUserByName(String name){
        return userMapper.selectUserByName(name);
    }
    //注册用户
    public Boolean register(User user){
        //先检查用户名是否存在
        User userByName = userMapper.selectUserByName(user.getUsername());
        if(userByName==null){
            //用户不存在才注册
            userMapper.addUser(user);
            //返回注册成功
            return true;
        }else {
            return false;
        }
    }
    //修改用户的金额
    public void changeMoney(Integer id, Double newMoney){
        userMapper.changeMoney(id,newMoney);
    }
}
